#include "StdAfx.h"
#include "cTexturesCube.h"


cTexturesCube::cTexturesCube(void)
{

}

cTexturesCube::~cTexturesCube(void)
{
	
}
int cTexturesCube::Init(const char fileName[6][255])
{
	glGenTextures( 1, &textureId);
	glBindTexture(GL_TEXTURE_CUBE_MAP, textureId);
	for (int i = 0; i < 6; ++i)
	{
		imageData[i] = LoadTGA(fileName[i], &width, &height,&bpp); 
		if(imageData[i])
		{
			glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, bpp==24 ? GL_RGB : GL_RGBA, width, height, 0, bpp==24?GL_RGB:GL_RGBA, GL_UNSIGNED_BYTE, imageData[i]);
		}
	}
	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	//glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
	glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
	glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
	destroy();
	return 0;
}
void cTexturesCube::destroy()
{
	if(imageData)
	{
		for(int i=0;i<6;i++)
			if(imageData[i])
				delete []imageData[i];

	}
}
